package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.hr.dto.OnJobRecordAddDTO;
import org.jsola.hr.dto.OnJobRecordUpdateDTO;
import org.jsola.hr.entity.OnJobRecordDO;
import org.jsola.hr.query.OnJobRecordQuery;
import org.jsola.hr.service.IOnJobRecordService;
import org.jsola.hr.vo.OnJobRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 在职记录表
 *
 * @author zhr
 */
@Component
public class OnJobRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private IOnJobRecordService onJobRecordService;

    /**
     * 生成add测试数据
     * @return OnJobRecordAddDTO
     */
    public OnJobRecordAddDTO getOnJobRecordAddDTO(){
        OnJobRecordAddDTO onJobRecordAddDTO = new OnJobRecordAddDTO();
        onJobRecordAddDTO.setEmpId(getRandomValue("varchar",32));
        onJobRecordAddDTO.setCompanyId(getRandomValue("varchar",32));
        onJobRecordAddDTO.setJoinDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        onJobRecordAddDTO.setTurnStraightDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        onJobRecordAddDTO.setLeaveDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        return onJobRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return OnJobRecordUpdateDTO
     */
    public OnJobRecordUpdateDTO getOnJobRecordUpdateDTO(OnJobRecordVO onJobRecordVO){
        return onJobRecordService.selectDOById(onJobRecordVO.getId(), SITE_ID).to(OnJobRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return OnJobRecordQuery
     */
    public OnJobRecordQuery getOnJobRecordQuery() {
        OnJobRecordQuery onJobRecordQuery = new OnJobRecordQuery();
        List<OnJobRecordDO> onJobRecordDOList = onJobRecordService.list(new OnJobRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(onJobRecordDOList)) {
            OnJobRecordDO onJobRecordDO = onJobRecordDOList.get(0);
            onJobRecordQuery = onJobRecordDO.to(OnJobRecordQuery.class);
        }
        return onJobRecordQuery;
    }

    /**
     * 保存示例
     * @return OnJobRecordVO
     */
    public OnJobRecordVO saveOnJobRecordExample(){
        OnJobRecordAddDTO addDTO = this.getOnJobRecordAddDTO();
        OnJobRecordVO onJobRecordVO = onJobRecordService.save(addDTO,buildTokenUser());
        return onJobRecordVO;
    }


}

